package api.cie.rss;

import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import api.cie.rss.dal.CategoryDAL;
import api.cie.rss.dal.DatabaseAdapter;

public class AddCategory extends Activity implements View.OnClickListener{

	private Button annuler;
	private Button ajout;
	private EditText nomCat;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_category);
	    nomCat = (EditText)findViewById(R.id.nomCategory);
		annuler = (Button)findViewById(R.id.btnAnlCategory);
		annuler.setOnClickListener(this);
		
        ajout = (Button)findViewById(R.id.btnAjoutCategory);
		ajout.setOnClickListener(this);
        
	}
	
	@Override
	public void onClick(View view) {
		if (view == ajout) {
			String nomCategorie = nomCat.getText().toString();
			if(!nomCategorie.equals("")){
				DatabaseAdapter dbAdapter = new DatabaseAdapter(this);
				dbAdapter.open();
				CategoryDAL categoryDAL = new CategoryDAL(dbAdapter);
				categoryDAL.createCategory(nomCategorie);
				dbAdapter.close();
			}
			Intent intent1 = new Intent(this, CategoryActivity.class);
			startActivity(intent1);
		}
		else if(view == annuler){
			Intent intent = new Intent(this, CategoryActivity.class);
			startActivity(intent);
		}
		
	}

}
